<html>
<head><meta charset="utf-8"><title>run mir-typeck on constants before evaluating them · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html">run mir-typeck on constants before evaluating them</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232626558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/run%20mir-typeck%20on%20constants%20before%20evaluating%20them/near/232626558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html#232626558">(Mar 31 2021 at 16:55)</a>:</h4>
<p>We have lots of fun bugs around evaluating constants during typeck, because we sometimes even do that when the constant itself has a type error. One solution could be to run the mir typechecker on the constant's body before evaluating it.</p>



<a name="232626870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/run%20mir-typeck%20on%20constants%20before%20evaluating%20them/near/232626870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html#232626870">(Mar 31 2021 at 16:57)</a>:</h4>
<p>It may be more expensive than just checking that all predicates on a constant hold and then hoping for the best during evaluation, but it is also more precise, as we'd only typeck the parts that we need post-monomorphization instead of assuming that generic predicates have been proven by the caller and trying to prove all predicates.</p>



<a name="232629517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/run%20mir-typeck%20on%20constants%20before%20evaluating%20them/near/232629517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html#232629517">(Mar 31 2021 at 17:13)</a>:</h4>
<p>so that i don't forget it while i am on a week long break... at least for the "incorrect substitution" problem we have in <a class="stream" data-stream-id="260443" href="/#narrow/stream/260443-project-const-generics">#project-const-generics</a>, it should be enough to only check the substituted param env of the constant once the constant itself isn't part of its own param env anymore</p>



<a name="232629675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/run%20mir-typeck%20on%20constants%20before%20evaluating%20them/near/232629675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html#232629675">(Mar 31 2021 at 17:14)</a>:</h4>
<p>this is something we have to do anyways to deal with the following causing a cycle error</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">4</span><span class="p">]</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="mi">3</span><span class="w"></span>
<span class="p">}]</span>: <span class="nb">Sized</span> <span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="232925138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/run%20mir-typeck%20on%20constants%20before%20evaluating%20them/near/232925138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/run.20mir-typeck.20on.20constants.20before.20evaluating.20them.html#232925138">(Apr 02 2021 at 17:10)</a>:</h4>
<p>one example of this problem is <a href="https://github.com/rust-lang/rust/issues/79047">https://github.com/rust-lang/rust/issues/79047</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>